import 'package:app/core/rtc/base/session_type.dart';
import 'package:app/global_widgets/message_item.dart';
import 'package:app/page/chat/state.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:get/get.dart';

import 'logic.dart';

class ChatPage extends StatelessWidget {
  final ChatLogic _logic = Get.find<ChatLogic>();
  final ChatState _state = Get.find<ChatLogic>().state;
  final _arguments = Get.arguments; // name type phone

  @override
  Widget build(BuildContext context) {
    return GetBuilder<ChatLogic>(builder: (_) {
      return _normalChat();
    });
  }

  // 常规聊天
  Widget _normalChat() {
    return Scaffold(
        appBar: AppBar(
          title: Text('${_arguments["name"]}'),
          centerTitle: true,
        ),
        body: SafeArea(
          maintainBottomViewPadding: true,
          child: Container(
              child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                Expanded(
                  child: Padding(
                    padding: EdgeInsets.all(8),
                    child: ListView.builder(
                      itemBuilder: (context, index) {
                        return MessageItem(_state.message[index]);
                      },
                      itemCount: _state.message.length,
                    ),
                  ),
                  flex: 18,
                ),
                Expanded(
                  child: Container(
                    child: Row(
                      children: [
                        Expanded(
                          child: TextField(
                              autofocus: false,
                              textInputAction: TextInputAction.send,
                              decoration: InputDecoration(
                                  isDense: true,
                                  // border: kInputBorder,
                                  contentPadding: EdgeInsets.symmetric(
                                      vertical: 5.0, horizontal: 15))),
                          flex: 5,
                        ),
                        Expanded(
                          child: IconButton(
                              icon: Icon(Icons.send_rounded,
                                  color: Colors.lightBlueAccent),
                              onPressed: () {}),
                        ),
                      ],
                    ),
                  ),
                  flex: 2,
                ),
                //TODO 后期处理
                Expanded(
                  child: _normalActionView(),
                  flex: 2,
                )
              ])),
        ));
  }

  SingleChildScrollView _normalActionView() {
    return SingleChildScrollView(
      child: Container(
          height: 60,
          child: Row(
            children: [
              Expanded(
                  child: IconButton(
                      onPressed: () {
                        _logic.call(_arguments["name"], SessionType.VIDEO,
                            _arguments["phone"]);
                      },
                      icon: Icon(Icons.video_call_rounded))),
              Expanded(
                  child: IconButton(
                      onPressed: () {
                        _logic.call(_arguments["name"], SessionType.VIDEO,
                            _arguments["phone"],
                            isShareScreen: true);
                      },
                      icon: Icon(Icons.screen_share))),
              Expanded(
                  child: IconButton(
                      onPressed: () {
                        _logic.call(_arguments["name"], SessionType.AUDIO,
                            _arguments["phone"]);
                      },
                      icon: Icon(Icons.call))),
              Expanded(
                  child: IconButton(
                      onPressed: () {}, icon: Icon(Icons.photo_camera))),
            ],
          )),
    );
  }
}
